	var imagesList = [];
    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value 

    // Wait for PhoneGap to connect with the device
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // PhoneGap is ready to be used!
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

  

    // A button will call this function
    //
    function capturePhoto() {
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 25, destinationType: Camera.DestinationType.FILE_URI });
}

function onPhotoURISuccess(imageURI) {
    createFileEntry(imageURI);
}

function createFileEntry(imageURI) {
    window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail);    
}

function copyPhoto(fileEntry) {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { 
        fileSys.root.getDirectory("DCIM/Camera", {create: true, exclusive: false}, function(dir) { 
                fileEntry.copyTo(dir, new Date().getTime()+".jpeg", onCopySuccess, fail); 
            }, fail); 
    }, fail); 
}

function onCopySuccess(entry) {
    console.log(entry.fullPath)
}

function fail(error) {
    console.log(error.code);
}

function getfiles()
{
 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);

}
function onFileSystemSuccess(fileSystem) {
    //fileSystem.root.getDirectory("csdphotos", {create: false, exclusive: false}, getDirSuccess, fail);
    fileSystem.root.getDirectory("DCIM/Camera", {create: false, exclusive: false}, getDirSuccess, fail);
}

function getDirSuccess(dirEntry) {
    // Get a directory reader
    var directoryReader = dirEntry.createReader();

    // Get a list of all the entries in the directory
    directoryReader.readEntries(readerSuccess,fail);
}

function readerSuccess(entries) {
    var i;
    for (i=0; i<entries.length; i++) {
    
    console.log("File : "+entries[i].fullPath);
    imagesList.push(entries[i].fullPath);
        // Assuming everything in the Music directory is an mp3, go nuts
        // otherwise check entries[i].name to see if it ends with .mp3
    }
    
    displayList();
}

function displayList() 
{
for(var i=0;i<imagesList.length;i++)
{
addRow(imagesList[i]);
}


}
function addRow(element1) 
{
	var table = document.getElementById("content");
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	var cell1 = row.insertCell(0);
	
	
	cell1.innerHTML = "<input type='checkbox' id="+element1+" value="+element1+" onClick='getResult(this.id)'><b>"+element1+"</b><img src='"+element1+"' height='42' width='42' /> <br>";
	
}

function getResult(clicked_id)
{
    alert(clicked_id);
   
}

 function deleteAllRows()
{
    try {
    var table = document.getElementById("content");
    var rowCount = table.rows.length;

    for(var i=0; i<rowCount; i++) {
        
            table.deleteRow(i);
            rowCount--;
            i--;
     
    }
    }catch(e) {
         console.log(e);
    }
}
 
   
    // Called if something bad happens.
    // 
    function onFail(message) {
      alert('Failed because: ' + message);
    }
